package com.yehuishou.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuishou.pojo.GuestBook;
import com.yehuishou.pojo.Itempl;
import com.yehuishou.pojo.SelItemParameter;
import com.yehuishou.service.EvaluateService;

@Controller
public class EvaluateController {
	@Resource
	private EvaluateService evaluateservice;
	
	//查询回收商品评论
	@RequestMapping("backEvaluate")
	public String backEvaluate(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, GuestBook gb,
			HttpServletRequest request){
		PageInfo<GuestBook> pageinfo=evaluateservice.backEvaluate(pageNum,pageSize,gb);
		request.setAttribute("pageinfo", pageinfo);
		request.setAttribute("gb", gb);
		return "backitem_evaluate";
	}
	
	
	//删除回收商品评论
	@ResponseBody
	@RequestMapping("backEvaluateDel")
	public int backEvaluateDel(Integer id) {
		int i = evaluateservice.backEvaluateDel(id);
		if (i > 0) {
			return 1;
		}
		return 2;
	}
	
	//批量删除
	@ResponseBody
	@RequestMapping("deletebpl")
	public Boolean deletebpl(@RequestParam(value = "td_s[]") Integer [] td_s) {
		for (Integer integer : td_s) {
			evaluateservice.backEvaluateDel(integer);
		}
		
		return true;
	}
	
	//查询出售商品评论
	@RequestMapping("itemEvaluate")
	public String itemEvaluate(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, Itempl ipl,
			Model model){
		PageHelper.startPage(pageNum, pageSize);
		List<Itempl> list = evaluateservice.itemEvaluate(ipl);
		PageInfo<Itempl> page = new PageInfo<Itempl>(list);
		model.addAttribute("page", page);
	    model.addAttribute("list",list);
	    model.addAttribute("ipl", ipl);
		return "item_evaluate";
	}
	
	//删除出售商品评论
	@ResponseBody
	@RequestMapping("itemEvaluateDel")
	public int itemEvaluateDel(Integer id) {
		int i = evaluateservice.itemEvaluateDel(id);
		if (i > 0) {
			return 1;
		}
		return 2;
	}
	
	//批量 deleteitp
	@ResponseBody
	@RequestMapping("deleteitp")
	public Boolean deleteitp(@RequestParam(value = "td_s[]") Integer [] td_s) {
		for (Integer integer : td_s) {
			evaluateservice.itemEvaluateDel(integer);
		}
		
		return true;
	}
	
}
